package com.example.mqtt_mode.mqtt.controller;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.example.mqtt_mode.mqtt.generator.service.PublishMessageService;
import com.example.mqtt_mode.mqtt.model.Equipment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author IT空门_门主
 * @date 2024/1/8
 * 发布消息
 */
@Slf4j
@RestController
@RequestMapping("/mqtt")
public class MessagePublishController {
    @Autowired
    private PublishMessageService publishMessageService;

    /**
     *测试发布消息
     */
    @GetMapping("publishMessage")
    public String publishMessage(String message){
//        String message = "小刘子真帅";
        publishMessageService.publishMessage(message);
        return "发布消息成功";
    }
    /**
     *测试发布消息
     */
    @PostMapping("publishMessageTest")
    public String publishMessageTest(@RequestBody Equipment equipment){
          log.info("设备信息：{}",equipment);
        String message = JSONUtil.toJsonPrettyStr(equipment);
//        String message = "小刘子真帅";
        publishMessageService.publishMessage(message);
        return "发布消息成功";
    }
}
